<?php
session_start();
include_once("conn.php");
if(isset($_GET["uname"]))
{
	//$u_id = $_GET["uid"];		//用户ID
	$u_name = $_GET["uname"];	//用户名字

	$sql = "select * from bbs_user where u_name = '".$u_name."'";
	$result = mysql_query($sql);
	$q_result = mysql_fetch_array($result);

	$u_sex = $q_result["u_sex"];						//性别
	$u_regtime = $q_result["u_regtime"];					//注册时间
	$u_lastlogintime = $q_result["u_lastlogintime"];	//最后登录时间
	$u_lastloginip = $q_result["u_lastloginip"];	//最后登录IP
	$u_count = $q_result["u_count"];		//登录次数统计

	if($u_sex == 1)
	{
		$u_sex = "男";
		$it = "他";
	}
	else {
		$u_sex = "女";
		$it = "她";
	}

	$sql = "select count(*) as wen_count from bbs_topic where t_author = '".$u_name."'";
	$result = mysql_query($sql);
	$q_result = mysql_fetch_array($result);

	$wen_count = $q_result["wen_count"];		//发表的主题数

	$sql = "select count(*) as reply_count from bbs_reply where r_u_name = '".$u_name."'";
	$result = mysql_query($sql);
	$q_result = mysql_fetch_array($result);

	$reply_count = $q_result["reply_count"];		//发表的回帖数

	//$u_admin = $q_result["u_admin"];			//是否管理员 是为1，此功能暂时不成立

	




}

if(isset($_GET["board"]))
{
	$board_name = $_GET["board"];
}

?>
<html>
<head>
<meta charset = "utf-8" />
<title>查看用户信息</title>
<link rel = "stylesheet" href = "sidebar.css" type = "text/css" />
<link rel = "stylesheet" href = "profile.css" type = "text/css" />
</head>
<body>
<?php
include_once("sidebar.php");
?>
<div class = "header">
<p><img src = "photos/find_friend.gif"></p>
<hr>
</div>

<div class = "friend">
<table>
<tr>
	<td>用户名:<?php echo $u_name; ?>&nbsp</td>
	<td>性别:<?php echo $u_sex; ?>&nbsp</td>
	<td>共上站有&nbsp<?php echo $u_count; ?>&nbsp次&nbsp</td>
</tr>
<tr>
	<td>共发表了&nbsp<?php echo $wen_count; ?>&nbsp篇主题&nbsp</td>
	<td>以及&nbsp<?php echo $reply_count; ?>&nbsp篇回复&nbsp</td>
</tr>
<tr>
	<td>注册时间是&nbsp<?php echo $u_regtime; ?>&nbsp</td>
</tr>
<tr>
	<td>最后上线时间是&nbsp<?php echo $u_lastlogintime;  ?>&nbsp</td>
</tr>
<tr>
	<td><input type = "button" onclick = "history.back()" value = "返回前页"></td>
</tr>
</table>

</div>

<table id = "tb_article" >

<tr>
<th><?php echo $it ?>的发言</th>
<th>发帖时间</th>
<th>所在版面</th>
</tr>
<?php
	$page_size = 20;			//每页主题数目

	if(isset($_GET["page"]))
	{
		$page_num = $_GET["page"];
	}
	else {
		$page_num = 1;					//当前页码
	}

	

	$offset = ($page_num-1)*$page_size;		//偏移量用于limit查询

	$sql = "select count(*) as total from bbs_topic where t_author = '".$u_name."'";
	$result = mysql_query($sql);
	
	
	$q_result = mysql_fetch_array($result);
	$total = $q_result["total"];				//文章总数 
	$page_count = ceil($total/$page_size);		//最大页数

	$first = 1;
	$last = $page_count;
	$next = $page_num+1;
	$prev = $page_num-1;


	$sql = "select * from bbs_topic where t_author = '".$u_name."' order by t_time desc limit ".$offset.",".$page_size."";
	$result = mysql_query($sql);
	//$q_result = mysql_fetch_array($result);

	while($q_result = mysql_fetch_array($result))
	{
		$t_topic = $q_result["t_topic"];				//主题题目
		$t_time = $q_result["t_time"];					//发帖时间
		$t_session_name = $q_result["t_session_name"];	//主题所在版
		$t_id = $q_result["t_id"];						//主题ID
		
?>
		<tr>
			<td><a href = "browse.php?board=<?php echo $t_session_name; ?>&tid=<?php echo $t_id; ?>"><?php echo $t_topic; ?></a></td>
			<td><?php echo $t_time; ?></td>
			<td><a href = "page.php?board=<?php echo $t_session_name; ?>"><?php echo $t_session_name; ?></a></td>
		</tr>
<?php
	}

?>


</table>
<div class = "footer">

<tr>
<?php if($page_count>1 && $page_num==1  ) {  ?>
<a href = "profile.php?uname=<?php echo $u_name; ?>&page=<?php echo $next; ?>">下一页</a>&nbsp
<a href = "profile.php?uname=<?php echo $u_name; ?>&page=<?php echo $last; ?>">尾页</a>&nbsp
<?php } ?>
</tr>

<tr>
<?php 
if($page_count == 1)
{
?>
<a href = "profile.php?uname=<?php echo $u_name; ?>&page=<?php echo $first; ?>">首页</a>&nbsp
<?php }?>
</tr>

<tr>
<?php
if($page_count>1 && $page_num>1 && $page_num!=$page_count)
{
?>
<a href = "profile.php?uname=<?php echo $u_name; ?>&page=<?php echo $first; ?>">首页</a>&nbsp
<a href = "profile.php?uname=<?php echo $u_name; ?>&page=<?php echo $prev; ?>">上一页</a>&nbsp
<a href = "profile.php?uname=<?php echo $u_name; ?>&page=<?php echo $next; ?>">下一页</a>&nbsp
<a href = "profile.php?uname=<?php echo $u_name; ?>&page=<?php echo $last; ?>">尾页</a>&nbsp
<?php } ?>
</tr>

<tr>
<?php
if($page_num==$page_count && $page_count>1)
{
?>
<a href = "profile.php?uname=<?php echo $u_name; ?>&page=<?php echo $first; ?>">首页</a>&nbsp
<a href = "profile.php?uname=<?php echo $u_name; ?>&page=<?php echo $prev; ?>">上一页</a>&nbsp
<?php } ?>
</tr>

</div>
</body>
</html>